package junit;

import base.Identifier;
import base.Interpreter;
import expressions.*;
import instructions.*;
import values.Integer;

public class LocalTest {

	// local(x,y,z) {
	// x = 4;
	// y = 5;
	// local(x,y) {
	// x = 2;
	// y = 3;
	// print(x + y)
	// }
	// z = x + y;
	// print(z)
	// }

	public static void main(String[] args) {

		Identifier x = new Identifier("x");
		Identifier y = new Identifier("y");
		Identifier z = new Identifier("z");

		VariableAssign innerVax = new VariableAssign(x, new Integer(2));
		VariableAssign innerVay = new VariableAssign(y, new Integer(3));
		Print innerPrint = new Print(new Add(new VariableAccess(x),
				new VariableAccess(y)));
		Composition innerCompo1 = new Composition(innerVax, innerVay);
		Composition innerCompo2 = new Composition(innerCompo1, innerPrint);
		Local innerLocalx = new Local(x, innerCompo2);
		Local innerLocaly = new Local(y, innerLocalx);

		VariableAssign vax = new VariableAssign(x, new Integer(4));
		VariableAssign vay = new VariableAssign(y, new Integer(5));

		Composition compo1 = new Composition(vax, vay);
		Composition compo2 = new Composition(compo1, innerLocaly);

		VariableAssign vaz = new VariableAssign(z, new Add(
				new VariableAccess(x), new VariableAccess(y)));

		Composition compo3 = new Composition(compo2, vaz);

		Print print = new Print(new VariableAccess(z));

		Composition compo = new Composition(compo3, print);

		Local xlocal = new Local(x, compo);
		Local ylocal = new Local(y, xlocal);
		Local zlocal = new Local(z, ylocal);

		Interpreter.instr(zlocal);
	}
}
